package com.codingclub.oss.config;

import com.codingclub.oss.adapter.MinioServerAdapter;
import com.codingclub.oss.adapter.OssServerAdapter;
import com.codingclub.oss.enums.OssServerEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class OssServerConfig {

    private final String serverType;

    public OssServerConfig(@Value("${oss.server.type}") String serverType) {
        this.serverType = serverType;
    }
    @Bean
    public OssServerAdapter getOssServer(@Value("${oss.server.type}") String serverType){
        if(StringUtils.isBlank(serverType)){
            throw new RuntimeException("没有配置oss服务类型");
        }
        if(OssServerEnum.MINIO.getType().equals(serverType)){
            return new MinioServerAdapter();
        }else if(OssServerEnum.ALIYUN.getType().equals(serverType)){
           return null;//根据传入的类型进行配置相应的处理器
        }else{
            throw new IllegalArgumentException("未匹配到oss对象存储处理器");
        }
    }
}
